var index = 0;
function news() {
  const ul = document.getElementsByClassName("new_img_ul")[0];
  let lis = ul.getElementsByTagName("figure");
  let timer = null;
  

  //要轮播的图片路径
  let figure_list = [
    "./img/8.jpg",
    "./img/9.jpg",
    "./img/7.jpg",
    "./img/1.png",
    "./img/2.png",
    "./img/3.png",
  ];
  //要轮播的图片的标题
  let figure_text_list = [
    "江西省原副省长胡振鹏教授出席我校资源与环境学科建设研讨会",
    "资源环境学院开展原封建设年活动",
    "首期鄱阳湖课堂开讲了！",
    "首期长江生态文明实验班开班啦！",
    "校领导到资源环境学院调研指导申硕工作",
    "校领导深入资源环境学院开展教育思想大讨论调研工作",
  ];

  let figure_text_href = [
    "https://zhxy.jju.edu.cn/info/1088/2373.htm",
    "https://zhxy.jju.edu.cn/info/1088/2375.htm",
    "https://zhxy.jju.edu.cn/info/1088/2374.htm",
    "https://zhxy.jju.edu.cn/info/1088/2077.htm",
    "https://zhxy.jju.edu.cn/info/1088/2195.htm",
    "https://zhxy.jju.edu.cn/info/1088/2047.htm"
  ];

  //获取figure中的img标签
  let figure_img_1 = document.getElementById("figure_img_1");
  //获取figure中的a标签
  let figure_a_text = document.getElementById("figure_text");
  let figure_a_img = document.getElementById("figure_a_img");
  //获取图片下编号的ul
  const num_ul = document.getElementsByClassName("new_img_num")[0];
  //获取图片下编号的ul的li
  let num_li = num_ul.getElementsByTagName("li");

  

  //轮播函数
  function figure_lunbo(first) {
    index = first;
    timer = setInterval(function () {
     //给figure中a添加title实现鼠标悬停提示文字
      figure_a_text.title = figure_text_list[index];
      //修改图片路径
      figure_img_1.src = figure_list[index];
      //修改图片标题
      figure_a_text.textContent = figure_text_list[index];
      //修改href
      figure_a_text.href = figure_text_href[index];
      figure_a_img.href = figure_text_href[index];
      change(index);
      
      index = (index + 1) % figure_list.length;
    }, 3000);
  }
  //调用轮播函数
  figure_lunbo(1);

  //改变图片下编号颜色，透明度函数
  function change(m){
    let i = 0;
    for(i;i<figure_list.length;i++){
      num_li[i].className = 'inactive';
    }
    num_li[m].className = 'active';
  }

  console.log(num_li);

  //给图片下编号绑定单击事件
  let num_li_1 = num_li[0];
  let num_li_2 = num_li[1];
  let num_li_3 = num_li[2];
  let num_li_4 = num_li[3];
  let num_li_5 = num_li[4];
  let num_li_6 = num_li[5];
  num_li_1.onclick = function () {
    clearInterval(timer);
    figure_img_1.src = figure_list[0];
    figure_a_text.textContent = figure_text_list[0];
    figure_a_text.href = figure_text_href[0];
    figure_a_img.href = figure_text_href[0];
    change(0);
    figure_lunbo(1);
  };
  num_li_2.onclick = function () {
    clearInterval(timer);
    figure_img_1.src = figure_list[1];
    figure_a_text.textContent = figure_text_list[1];
    figure_a_text.href = figure_text_href[1];
    figure_a_img.href = figure_text_href[1];
    change(1);
    figure_lunbo(2);
  };
  num_li_3.onclick = function () {
    clearInterval(timer);
    figure_img_1.src = figure_list[2];
    figure_a_text.textContent = figure_text_list[2];
    figure_a_text.href = figure_text_href[2];
    figure_a_img.href = figure_text_href[2];
    change(2);
    figure_lunbo(3);
  };
  num_li_4.onclick = function () {
    clearInterval(timer);
    figure_img_1.src = figure_list[3];
    figure_a_text.textContent = figure_text_list[3];
    figure_a_text.href = figure_text_href[3];
    figure_a_img.href = figure_text_href[3];
    change(3);
    figure_lunbo(4);
  };
  num_li_5.onclick = function () {
    clearInterval(timer);
    figure_img_1.src = figure_list[4];
    figure_a_text.textContent = figure_text_list[4];
    figure_a_text.href = figure_text_href[4];
    figure_a_img.href = figure_text_href[4];
    change(4);
    figure_lunbo(5);
  };
  num_li_6.onclick = function () {
    clearInterval(timer);
    figure_img_1.src = figure_list[5];
    figure_a_text.textContent = figure_text_list[5];
    figure_a_text.href = figure_text_href[5];
    figure_a_img.href = figure_text_href[5];
    change(5);
    figure_lunbo(0);
  };
}
